#include "http_header.hpp"
#include "httputil.h"

http_header_t::http_header_t()
{
    m_maphttptable.clear();
    m_strmethod.clear();
}
http_header_t::~http_header_t()
{
}
void http_header_t::reset()
{
    m_maphttptable.clear();
    m_strmethod.clear();
}
const char* http_header_t::build_res()
{
    return m_strresheader.c_str();
}
void http_header_t::build_res_http()
{
    m_strresheader.append(m_strmethod.c_str());
    m_strresheader.append(" ");
    m_strresheader.append(HTTP_END);

    std::map<string, string>::iterator it = m_maphttptable.begin();

    while (it != m_maphttptable.end()) {
        m_strresheader += (*it).first.c_str();
        m_strresheader += ":";
        m_strresheader += (*it).second.c_str();
        m_strresheader += HTTP_END;
        it++;
    }
    m_strresheader += HTTP_END;
}
size_t http_header_t::build_res_len()
{
    return m_strresheader.length();
}
void http_header_t::build_req_http()
{
}
const char* http_header_t::build_req()
{
    return m_strreqheader.c_str();
}
size_t http_header_t::build_req_len()
{
    return m_strreqheader.length();
}

int http_header_t::add_cookie(const char* name, const char* value, const char* domain, const char* path, time_t expires)
{
    return 1;
}
int http_header_t::add_entry(const char* name, const char* value, bool replace)
{
    return 1;
}
int http_header_t::set_method(const char* method)
{
    m_strmethod.clear();
    m_strmethod.append(method);
    return 1;
}
int http_header_t::set_host(const char* host)
{
    m_maphttptable[HTTP_HOST] = host;
    return 1;
}
int http_header_t::set_accept(const char* accept)
{
    m_maphttptable[HTTP_ACCEPT] = string(accept);
    return 1;
}
int http_header_t::set_accept_charset(const char* charset)
{
    m_maphttptable[HTTP_ACCEPT_CHARSET] = charset;
    return 1;
}
int http_header_t::set_accept_encoding(const char* encoding)
{
    m_maphttptable[HTTP_ACCEPT_ENCODEING] = encoding;
    return 1;
}
int http_header_t::set_accept_datetime(const char* datetime)
{
    m_maphttptable[HTTP_ACCEPT_DATETIME] = datetime;
    return 1;
}
int http_header_t::set_accept_language(const char* language)
{
    m_maphttptable[HTTP_ACCEPT_LANGUAGE] = language;
    return 1;
}
int http_header_t::set_authorization(const char* authorization)
{
    m_maphttptable[HTTP_AUTHORIZATION] = authorization;
    return 1;
}
int http_header_t::set_cache_control(const char* cachecontrol)
{
    m_maphttptable[HTTP_CACHE_CONTROL] = cachecontrol;
    return 1;
}
int http_header_t::set_connection(const char* connection)
{
    m_maphttptable[HTTP_CONNECTION] = connection;
    return 1;
}
int http_header_t::set_content_md5(const char* md5)
{
    m_maphttptable[HTTP_CONTEND_MD5] = md5;
    return 1;
}
int http_header_t::set_content_type(const char* value)
{
    m_maphttptable[HTTP_CONTENT_TYPE] = value;
    return 1;
}
int http_header_t::set_dnt(const char* value)
{
    m_maphttptable[HTTP_DNT] = value;
    return 1;
}
int http_header_t::set_data(const char* data)
{
    m_maphttptable[HTTP_DATA] = data;
    return 1;
}
int http_header_t::set_expect(const char* expect)
{
    m_maphttptable[HTTP_EXPECT] = expect;
    return 1;
}
int http_header_t::set_etag(const char* etag)
{
    m_maphttptable[HTTP_ETAG] = etag;
    return 1;
}
int http_header_t::set_forwarded(const char* forwarded)
{
    m_maphttptable[HTTP_FORWARDED] = forwarded;
    return 1;
}
int http_header_t::set_use_agent(const char* agent)
{
    m_maphttptable[HTTP_USE_AGENT] = agent;
    return 1;
}
int http_header_t::set_keepalive(const char* value)
{
    m_maphttptable[HTTP_KEEPALIVE] = value;
    return 1;
}
int http_header_t::set_referer(const char* url)
{
    m_maphttptable[HTTP_REFERER] = url;
    return 1;
}
int http_header_t::set_range(const char* value)
{
    m_maphttptable[HTTP_RANGE] = value;
    return 1;
}
int http_header_t::set_upgrade_insecure_requests(const char* value)
{
    m_maphttptable[HTTP_UPGRADE_INSECURE_REQUESTS] = value;
    return 1;
}
int http_header_t::accept_gzip(bool on)
{
    return 1;
}
int http_header_t::set_status(int status)
{
    return 1;
}
int http_header_t::set_chunked(bool on)
{
    return 1;
}
int http_header_t::set_cgi_mode(bool on)
{
    return 1;
}
int http_header_t::set_transfer_gzip(bool on)
{
    return 1;
}
int http_header_t::set_content_length(uint64 n)
{
    return 1;
}
